package classes.utils
{
	import mx.controls.Alert;
	import mx.formatters.DateFormatter;
	
	public class Utility
	{
		private static var instance:Utility;
		
		private var dateFormatter:DateFormatter = new DateFormatter();
		
		public static function getInstance():Utility{
			if(instance == null)
				instance = new Utility();
				
			return instance;
		} 
		
		public function Utility()
		{
			dateFormatter.formatString = "MM/DD/YYYY";
		}
		
		public function showAlert(msg:String, title:String):void{
			Alert.show(msg, title);
		} 
		
		public function formatDate(date:Date):String{
			return this.dateFormatter.format(date);
		}
		
		public function formatFriendlyDate(date:Date):String{
			return this.translateMonth(date.getMonth()) + " " /*+ (date.getDay()) + ", "*/ + date.fullYear;
		}
		
		//TODO: implement to work (DataGridColumn uses 2 args, data, DGC)
		public function formatAmount(n:*):String{
			if(n is Number)
				return (n as Number).toFixed(2);
			
			else return parseFloat(n).toFixed(2);
		}
		
		public function askUserConfirm(msg:String, title:String, action:Function):void{
			Alert.show(msg, title, Alert.YES | Alert.NO, null, action, null, Alert.NO);
		}
		
		public function showWaitCursor(cursorID:Number):Number{
			return 0;
		}
		
		public function removeWaitCursor(cursorID:Number):Number{
			return 0;
		}
		
		public function translateMonth(m:Number):String{
			switch(m){
				case 0:  return "January";
				case 1:  return "February";
				case 2:  return "March";
				case 3:  return "April";
				case 4:  return "May";
				case 5:  return "June";
				case 6:  return "July";
				case 7:  return "August";
				case 8:  return "September";
				case 9:  return "October";
				case 10: return "November";
				case 11: return "December";
				default: return "{ERROR PARSING MONTH}";
			}
		}

	}
}